package org.jetlinks.pro.things.impl.converter;

import com.alibaba.fastjson.JSONObject;
import org.jetlinks.pro.things.ThingMessageConverter;
import org.jetlinks.pro.things.ThingMessageConverterProvider;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.util.Map;

@Component
public class MappingThingMessageConverterProvider implements ThingMessageConverterProvider {
    @Override
    public String getId() {
        return "mapping";
    }

    @Override
    public String getName() {
        return "映射转换";
    }

    @Override
    public Mono<ThingMessageConverter> createConverter(Map<String, Object> configuration) {
        return Mono.just(new MappingThingMessageConverter(
            new JSONObject(configuration)
                .getJSONArray("mappings")
                .toJavaList(MappingThingMessageConverter.Mapping.class)));
    }
}
